<html>
<body>
<?php
require ("connection.php");
if (isset($_REQUEST['x'])) {
    $x = $_REQUEST['x'];
    $my_query = "select photo from Magazine_photo where Mag_id='$x'";
}
$cmd = mysql_query($my_query, $connection);
$i = 1;
echo "<form method='post' action='A_D_Mphoto.php?x=$x'>";
while ($row = mysql_fetch_array($cmd)) {
    $key = "photo" . $i;
    echo "$key<br>";
    echo "<input type='checkbox' name='" . $key . "' value='" . $row['photo'] . "'>" .
        "delete" . "<br>";
    echo "<img src=" . $row['photo'] . ">" . "<br>";
    $i++;
}
echo "<input type='submit' value='Submit'>";
echo "</form>";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $x = $_REQUEST['x'];
    $query = "select * from Magazine_photo where Mag_id=x";
    $result = mysql_query($my_query, $connection);
    $count = mysql_num_rows($result);
    while ($count != 0) {
        $key = "photo" . $count;
        if ((isset($_POST["$key"]))) {
            $url = $_POST["$key"];
            echo $url;
            $dquery = "DELETE FROM Magazine_photo WHERE photo='$url'";
            mysql_query($dquery);
        }
        $count--;
    }
}
?>
</body>
</html>